package com.example.mvvmdemo.activity.mtv;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import com.example.mvvmdemo.R;
import com.example.mvvmdemo.databinding.ActivityDatadetailBinding;
import com.example.mvvmdemo.http.mtv.MtvViewModel;

/**
 * User: Chentuisi
 * Date: 2023/8/8
 */
public class DataDetailActivity extends AppCompatActivity {

    private ActivityDatadetailBinding binding;
    private MtvViewModel mtvViewModel;

    public static void toIntent(Context context, String id) {
        Intent intent = new Intent(context, DataDetailActivity.class);
        intent.putExtra("id", id);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_datadetail);
        mtvViewModel = new ViewModelProvider(this).get(MtvViewModel.class);
        binding.setLifecycleOwner(this);
        binding.setHandler(this);
        initViewModel();
        initView();
    }

    private void initViewModel(){
        mtvViewModel.getMv().observe(this, movie -> {
            binding.setData(movie);
        });
    }

    private void initView(){
        mtvViewModel.getMvtvData(getIntent().getStringExtra("id"));
    }

}
